package com.lajiaomian.springbootruijiwaimai.service.impl.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lajiaomian.springbootruijiwaimai.common.R;
import com.lajiaomian.springbootruijiwaimai.mapper.EmployeeMapper;
import com.lajiaomian.springbootruijiwaimai.pojo.Employee;
import com.lajiaomian.springbootruijiwaimai.service.impl.EmployeeService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;

/**
 * @author lajiaomian
 * @create 2022-08-11-10:38
 */
@Service
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee>
        implements EmployeeService {

    @Override
    public Employee getEmployee(String username) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("username",username);
        return getOne(wrapper);
    }

    @Override
    public Page<Employee> getEmployeePage(Integer page,Integer pageSize,String name) {
        //配置分页信息
        Page pageInfo = new Page(page,pageSize);
        //显示指定用户信息
        QueryWrapper<Employee> wrapper = new QueryWrapper<>();
        wrapper.like(StringUtils.isNotEmpty(name),"username",name);
        //进行正序排列
        wrapper.orderByDesc("update_time");
        page(pageInfo, wrapper);
        return pageInfo;
    }
}
